package com.jlboot.core.handler;

import com.jfinal.handler.Handler;
import lombok.extern.slf4j.Slf4j;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author wangsanfei
 * @version 1.0
 * Create by 2024/5/17 14:32
 */
@Slf4j
public class GlobalHandler extends Handler {
    @Override
    public void handle(String target, HttpServletRequest request, HttpServletResponse response, boolean[] isHandled) {


        //文件特殊处理，如果是.jpe类的文件，jfinal会默认走静态路径，这里重置一下。注意其他地方不能使用/file开头的定义
        if(target.startsWith("/file")){
            request.setAttribute("fileName",target.replace("/file",""));
            next.handle("/file", request, response, isHandled);
            return;
        }


        //正常执行
        next.handle(target, request, response, isHandled);

    }



}
